package ar.edu.unrn.lia.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import ar.edu.unrn.lia.dao.TasaInteresDAO;
import ar.edu.unrn.lia.model.TasaInteres;
import ar.edu.unrn.lia.service.TasaInteresService;
import ar.edu.unrn.lia.service.exception.BusinessException;

@Named("tasaInteresService")
public class TasaInteresServiceImpl implements TasaInteresService, Serializable {

	

	/**
	 * 
	 */
	private static final long serialVersionUID = 5601895833648637227L;
	@Inject
	TasaInteresDAO entityDAO;

	public TasaInteresDAO getEntityDAO() {
		return entityDAO;
	}

	@Transactional(readOnly = true)
	public Long getCount(Map<String, String> filters) {
		return getEntityDAO().count(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters));
	}

	@Transactional(readOnly = true)
	public List<TasaInteres> getList(Integer page, Integer pagesize,
			Map<String, String> filters, String sortField, Boolean asc) {
		return getEntityDAO().listwithPag(
				getEntityDAO().getSearchPredicates(getEntityDAO().rootCount(),
						filters), page, pagesize, sortField, asc);
	}

	@Transactional
	public void save(TasaInteres entity) {

		getEntityDAO().create(entity);
	}

	@Transactional
	public void delete(TasaInteres entity) {
		getEntityDAO().delete(entity);
	}

	@Transactional
	public void update(TasaInteres entity) {
		getEntityDAO().update(entity);
	}

	public TasaInteres getEntityById(Long id) {
		return getEntityDAO().read(id);
	}

	public List<TasaInteres> getAll() {
		return getEntityDAO().findAll();
	}

	public List<TasaInteres> findByQuery(String query, String propertyFilter,
			String orderDirection) {
		return getEntityDAO()
				.findByQuery(query, propertyFilter, orderDirection);
	}
	
	public TasaInteres tasaInteresFechaHoy() throws BusinessException
	{
		TasaInteres ti = getEntityDAO().tasaInteresFechaHoy();
		if (ti == null)
			throw new BusinessException("No esta definida la Tasa de Interes que corresponde al correinte mes.");
		
		return ti;
	}

}